package com.agent.task;

import com.alibaba.fastjson.JSON;
import com.agent.logbean.WebLogBean;
import com.agent.service.OperationLogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by fangjicai on 2020/5/31.
 */
public class OperationLogThread implements Runnable{
    private static Logger logger= LoggerFactory.getLogger(OperationLogThread.class);
    private volatile OperationLogService operationLogService;
    private volatile WebLogBean webLogBean;

    public OperationLogThread(OperationLogService operationLogService,
                              WebLogBean webLogBean) {
        this.operationLogService=operationLogService;
        this.webLogBean=webLogBean;
    }

    @Override
    public void run() {
        try {
            if (logger.isInfoEnabled()) {
                logger.info("thread name " + Thread.currentThread().getName() + " start save operateLog " + JSON.toJSONString(webLogBean));
            }
            this.operationLogService.saveOperationLog(webLogBean);
            if (logger.isInfoEnabled()) {
                logger.info("thread name " + Thread.currentThread().getName() + "save operateLog success ");
            }
        } catch (Exception e) {
            logger.error("thread name "+Thread.currentThread().getName()+" save operateLog error",e);
        }
    }
}
